package com.softcloud.gamesbase;

import android.content.Context;
import android.content.Intent;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;


public class HeroPage extends BaseActivity {

    private List<Hero> heros = new ArrayList<Hero>();
    private ListView heroList;

    public static void actionStart(Context context,String gameName){
        Intent intent = new Intent(context,HeroPage.class);
        intent.putExtra("gameName",gameName);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_hero_page);
        Intent intent = getIntent();
        String gameName = intent.getStringExtra("gameName");
        switch (gameName){
            case "Dota":
                initDotaHeros();
                break;
            case "三国杀":
                initSanguoshaHeros();
                break;
            case "炉石传说":
                initHealthstoneHeros();
                break;
        }
        heroList = (ListView)findViewById(R.id.hero_list);
        HeroAdapter adapter = new HeroAdapter(HeroPage.this,R.layout.hero_item,heros);
        heroList.setAdapter(adapter);
        HeroItemListener heroItemListener = new HeroItemListener();
        heroList.setOnItemClickListener(heroItemListener);
    }

    class HeroItemListener implements AdapterView.OnItemClickListener{

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Hero hero = heros.get(position);
            IntroductionActivity.actionStart(HeroPage.this,hero);
        }
    }




    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_hero_page, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }


    private void initDotaHeros(){
        String axeName = "@String/axe";
        String axeDes = "@String/axe_des";
        String axeSkill1Name = "@String/axe1";
        String axeSkill2Name = "@String/axe2";
        String axeSkill3Name = "@String/axe3";
        String axeSkill4Name = "@String/axe4";
        String axeSkill1Des = "@String/axe1_des";
        String axeSkill2Des = "@String/axe2_des";
        String axeSkill3Des = "@String/axe3_des";
        String axeSkill4Des = "@String/axe4_des";
        HeroSkill axe1 = new HeroSkill(axeSkill1Name,axeSkill1Des,R.drawable.axe1);
        HeroSkill axe2 = new HeroSkill(axeSkill2Name,axeSkill2Des,R.drawable.axe2);
        HeroSkill axe3 = new HeroSkill(axeSkill3Name,axeSkill3Des,R.drawable.axe3);
        HeroSkill axe4 = new HeroSkill(axeSkill4Name,axeSkill4Des,R.drawable.axe4);
        Hero axe = new Hero(axeName,R.drawable.axe);
        axe.addSkill(axe1);
        axe.addSkill(axe2);
        axe.addSkill(axe3);
        axe.addSkill(axe4);
        axe.setHeroDes(axeDes);


        heros.add(axe);
    }
    private void initSanguoshaHeros(){

    }
    private void initHealthstoneHeros(){

    }

}
